package trlygjj.tanruiliyigenjinjin.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.SalaryTemplate;
import trlygjj.tanruiliyigenjinjin.service.ISalaryTemplateService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("salaryTemplate")
public class SalaryTemplateController {

    @Autowired
    private ISalaryTemplateService salaryTemplateService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @RequestMapping("")
    public String index(){
        return "salaryTemplate/list";
    }


    /**
     * 查询全部
     * @return
     */
    @RequestMapping("listAll")
    @ResponseBody
    public List<SalaryTemplate> listAll(){
        return salaryTemplateService.selectAll();
    }



    /**
     *更新
     * @param salaryTemplate 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(SalaryTemplate salaryTemplate){
        JsonResult result = new JsonResult();
        try{
            salaryTemplateService.updateByPrimaryKey(salaryTemplate);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param salaryTemplate 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(SalaryTemplate salaryTemplate){
        JsonResult result = new JsonResult();
        try{
            salaryTemplateService.insert(salaryTemplate);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }




    @RequestMapping("selectByEmployeeId")
    @ResponseBody
    public SalaryTemplate selectByEmployeeId(Long employeeId){
        return  salaryTemplateService.selectByEmployeeId(employeeId);
    }
}
